package com.bschlearn.group.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.bschlearn.group.message.BaseRsp;
/**
 * 
 * @ClassName: GroupExceptionHandler 
 * @Description: TODO(统一异常处理) 
 * @author dcc
 * @date 2019年10月30日 下午7:53:43 
 *
 */
@RestControllerAdvice
public class GroupExceptionHandler {
	
	private final static Logger log = LoggerFactory.getLogger(GroupExceptionHandler.class);
	
	@ExceptionHandler(value=Exception.class)
	public Object errorHandler(HttpServletRequest reqest, 
    		HttpServletResponse response, Exception e) throws Exception {
		
		log.error("异常：",e);
		
		return BaseRsp.errorException(e.getMessage());
		
	}
	
	/**
	 * 
	 * @Title: IMoocExceptionHandler.java
	 * @Description: 判断是否是ajax请求
	 * Copyright: Copyright (c) 2017
	 * Company:FURUIBOKE.SCIENCE.AND.TECHNOLOGY
	 * 
	 * @author leechenxiang
	 * @date 2017年12月3日 下午1:40:39
	 * @version V1.0
	 */
	public static boolean isAjax(HttpServletRequest httpRequest){
		return  (httpRequest.getHeader("X-Requested-With") != null  
					&& "XMLHttpRequest"
						.equals( httpRequest.getHeader("X-Requested-With").toString()) );
	}
}
